<?php

class FormListView extends FormControl {
	
	public static $property = array(
		'wbtype',
		'name',
		'caption',
		'x',
		'y',
		'width',
		'height',
		'lines',
		'disabled',
		'checkbox',
		'single',
		'sort',
		'visible'
	);
		
	public function __construct() { 
		parent::__construct(array(
			'wbtype' => 'ListView',
			'x' => 0,
			'y' => 0,
			'width' => 100,
			'height' => 100
		));
	}

	/**
	 * 컨트롤 그리기 
	 * 
	 * @param WBGraphics $graphics
	 */
	public function displayControl(WBGraphics $g) {

		$xstart = $this->getOption('x');
		$ystart = $this->getOption('y');
		$width = $this->getOption('width');
		$height = $this->getOption('height');		
		$caption = $this->getOption('caption');		
		$style = $this->getOption('style');		
		$value = $this->getOption('value');		
	
		$xend = $xstart + $width;
		$yend = $ystart + $height;	

	
		// draw editbox 
		$editbox = new FormEditBox();
		$editbox['x'] = $xstart;		
		$editbox['y'] = $ystart;		
		$editbox['width'] = $width;		
		$editbox['height'] = $height;		
		$editbox['caption'] = "";
		$editbox['disabled'] = $this['disabled'];
		$editbox->displayControl($g);

		// draw scrollbar
		$scrollbar = new FormScrollBar();
		$scrollbar['x'] = $xstart + $width - 19;		
		$scrollbar['y'] = $ystart + 1;		
		$scrollbar['width'] = 18;		
		$scrollbar['height'] = $height - 2;		
		$scrollbar['caption'] = $caption;
		$scrollbar['disabled'] = $this['disabled'];
		$scrollbar->displayControl($g);		
		
		$lwidth = $width - 18;
		$title = explode(',', $caption);
		$nhead = count($title);
		$xpos = $xstart + 1;
		// Draw header titles

		for($i = 0; $i < $nhead; $i++) {
			if($xpos < $lwidth - 36) {
				$size = wb_get_size($title[$i], null);
				$width = $size[0] + 20;
				
				// draw push button
				$pushbutton = new FormPushButton();
				$pushbutton['caption'] = " ";
				$pushbutton['x'] = $xpos;
				$pushbutton['y'] = $ystart + 1;
				$pushbutton['width'] = $width;
				$pushbutton['height'] = 16;
				$pushbutton['disabled'] = $this['disabled'];
				$pushbutton->displayControl($g);
				
				$font = ($this['disabled']) ? self::$disabledFont : self::$realFont ;				
				
				$g->text($title[$i], $xpos, $ystart + 1, $width, 16, $font, WBC_CENTER | WBC_MIDDLE);
				
				$xpos += $width;
				if($this->checkStyle('lines')) {
					$g->line($xpos, $ystart, $xpos, $ystart + $height, FormControl::SHADE);
				}
			}
		}
	
		// Draw last (blank) title if needed
	
		$width = $lwidth - $xpos + 18;
		if($width > 0) {
			// draw push button
			$pushbutton = new FormPushButton();
			$pushbutton['caption'] = " ";
			$pushbutton['x'] = $xpos;
			$pushbutton['y'] = $ystart + 1;
			$pushbutton['width'] = $width;
			$pushbutton['height'] = 16;
			$pushbutton['disabled'] = $this['disabled'];
			$pushbutton->displayControl($g);			
		}
	
		// Draw horizontal lines
	
		if($this->checkStyle('lines')) { 
			for($y = 30; $y < $height; $y += 13) {
				$g->line($xstart + 2, $ystart + $y, $xstart + $lwidth, $ystart + $y, FormControl::FACE);
			}
		}
	}
	
	public function getProperty() { 
		return self::$property;
	}	
}


?>